var router = require('libs/router').router;
var pages = require('libs/pages');
var ItemMixin = require('mixins/item');
var libs = require('libs/libs');
var api = libs.api;
var valide = libs.formValide;
var siteIntroduce

//当前页公共变量
var _page = {}


var bindEvent = function(){
    //此处各种dom 操作
    $(".managerBox").off().click(function (){
        var _src = $(this).attr('data-url');
        console.log(_src);
        var htmlstr = "<div class='ab_cover1'>";
        htmlstr += "<div class='mangBox'></div>";
        htmlstr += "</div>";
        $('body').append(htmlstr);
        $('.mangBox').append("<img src='"+_src+"' alt=''/>");
        $('.ab_cover1,.mangBox').off().click(function () {
            $('.mangBox,.ab_cover1').remove();
        });
    })

};

//演示模块
var SiteIntroduce = React.createClass({
    mixins: [ItemMixin],
    render:function(){
        var _data = this.props.data;
        var _servicesList = _data.serviceItemsList.map(function(item,index){
            return (
                <li key={index}><img src={item.url} /><span>{item.dicName}</span></li>
            );
        });

        var _manabarList = _data.responserList.map(function(item,index){
            return (
                <div key={index} data-url={item.url} className="managerBox">
                    <img src={item.extUrl} alt=""/>
                    <span className="managerName">{item.respName}</span>
                    <div className="starBox">
                        <i></i>
                        <i></i>
                        <i></i>
                        <i></i>
                        <i></i>
                    </div>
                    <span className="score">
                        {item.average}分
                    </span>
                </div>
            );
        });
        return (
            <div className="uc-siteIntroduce flex flex-v">
                <div className="flex-1 f-oTouch">
                    <div className="siteInfo box-shadow">
                        <div className="infoHead">
                            <img src={_data.imgFileList.length>0?_data.imgFileList[0].extUrl:''} alt=""/>
                            <div className="siteContact">
                                <span className="siteName">{_data.providerName}</span>
                                <span>{'联系电话：'+_data.contactPhone}</span>
                                <span>{'营业时间：'+_data.businessHours}</span>
                            </div>
                        </div>
                        <div className="infoFoot">
                            <label>地址：</label>
                            <p>{_data.contactAddress}</p>
                        </div>
                    </div>
                    <div className="services box-shadow">
                        <h4>服务项目</h4>
                        <ul className="servicesList">
                            {_servicesList}
                            {/*<li><i className="icon-print"></i><span>应急复印</span></li>
                            <li><i className="icon-tel"></i><span>应急电话</span></li>
                            <li><i className="icon-water"></i><span>应急饮水</span></li>
                            <li><i className="icon-rainGear"></i><span>应急雨具</span></li>
                            <li><i className="icon-wifi"></i><span>应急上网</span></li>
                            <li><i className="icon-nav"></i><span>寻路指路</span></li>
                            <li><i className="icon-express"></i><span>快递收发</span></li>
                            <li><i className="icon-charge"></i><span>应急充电</span></li>
                            <li><i className="icon-runner"></i><span>跑腿服务</span></li>
                            <li><i className="icon-send"></i><span>包裹寄送</span></li>*/}
                        </ul>
                    </div>
                    <div className="introduce box-shadow">
                        {_data.providerRma}
                    </div>
                    <div className="manager">
                        {_manabarList}
                    </div>
                </div>
            </div>
        );
    }
});

function start(name){
    return pages.new({
        boot:function(){},
        trigger:function(){
            this.libs.changeTitle('网点介绍');    //更改当前页面标题
            var login = SA.get('USER');
            if(login.info.currentCommunity){
                var params = {
                    method:'get',
                    communityId : login.info.currentCommunity.communityId     //网点ID
                };
                var _this = this;
                api.req('/getSiteMaintainInfoByApp',params,function(data){
                    _this.main(_this,data);
                })
            }else{
                router('uc/location')
            }
        },
        goback: function(){
            _user = SA.get('USER')
            var _pre = router.pre()
            if (_pre && _pre.hash === 'uc/location'){
                router.cb = function(){
                    if (wx){
                        wx.closeWindow()
                    }
                }
            }
            else
            if (_pre && _pre.hash === 'login'){
                router.cb = function(){
                    if (wx){
                        wx.closeWindow()
                    }
                }
            }
            else {
                router.cb = function(){
                    router.goback()
                }
            }
        },
        main: function(self ,data){
            if(!data.providerId){
                data = {
                    "businessHours":"",
                    "communityList":"",
                    "communitySize":"",
                    "contact":"",
                    "contactAddress":"",
                    "contactPhone":"",
                    "createBy":"",
                    "createTime":"",
                    "dscd":"",
                    "dscdListMap":"",
                    "headPhone":"",
                    "imgFileList":[],
                    "isDeleted":false,
                    "providerCode":"",
                    "providerId":"",
                    "providerName":"",
                    "providerRma":"",
                    "providerZone":"",
                    "responserList":[],
                    "serviceItemsList":[],
                    "sourceCode":"",
                    "sourceType":"",
                    "type":"",
                    "updateBy":"",
                    "updateTime":"",
                    "version":""
                };
            }
            if(data){
                siteIntroduce = data
                SA.runner('_wxShare', {provideImg: data.imgFileList})
            }
            this.render(
                <SiteIntroduce itemDefaultMethod={bindEvent} data={data} />,
                document.getElementById(name)
            )
        },
        end: function(){
            React.unmountComponentAtNode(document.getElementById(name));
            $('.mangBox,.ab_cover1').remove();
        }
    })
}

module.exports = start;
